package com.wuxiaolong.backend.controller;

import com.wuxiaolong.backend.model.JsonResult;
import com.wuxiaolong.backend.model.Permission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author Leo
 * @date 2020-04-19
 */
@Slf4j
@RestController
public class HomeController {

    @ResponseBody
    @RequestMapping(value = {"/menus"}, method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    public JsonResult<List<Permission>> login(@RequestHeader HttpHeaders httpHeaders, HttpServletRequest req) {
        log.debug("获得所有菜单列表");
        // todo 根据用户角色和权限信息过滤出该用户的菜单列表


        /**
         *       // 菜单图标，最好配置到数据库中
         *       iconsObj: {
         *         125: 'iconfont icon-user',
         *         103: 'iconfont icon-tijikongjian',
         *         101: 'iconfont icon-shangpin',
         *         102: 'iconfont icon-danju',
         *         145: 'iconfont icon-baobiao'
         *       }
         */

        Permission p1 = new Permission();
        p1.setId(1);
        p1.setPermissionLevel("1");
        p1.setApiPath("");
        p1.setPermissionName("用户管理");
        p1.setIcon("iconfont icon-tijikongjian");
        p1.setPid(0);

        List<Permission> list1 = new ArrayList<>();
        Permission p11 = new Permission();
        p11.setId(11);
        p11.setPermissionLevel("11");
        p11.setApiPath("/user");
        p11.setPermissionName("用户列表");
        p11.setIcon("iconfont icon-user");
        p11.setPid(1);
        list1.add(p11);

        Permission p12 = new Permission();
        p12.setId(12);
        p12.setPermissionLevel("12");
        p12.setApiPath("/role");
        p12.setPermissionName("角色列表");
        p12.setIcon("iconfont icon-baobiao");
        p12.setPid(1);
        list1.add(p12);

        Permission p13 = new Permission();
        p13.setId(13);
        p13.setPermissionLevel("13");
        p13.setApiPath("/permission");
        p13.setPermissionName("权限列表");
        p13.setIcon("iconfont icon-danju");
        p13.setPid(1);
        list1.add(p13);

        p1.setChildren(list1);



        Permission p2 = new Permission();
        p2.setId(2);
        p2.setPermissionLevel("2");
        p2.setApiPath("");
        p2.setPermissionName("商品管理");
        p2.setIcon("iconfont icon-shangpin");
        p2.setPid(0);

        List<Permission> list2 = new ArrayList<>();
        Permission p22 = new Permission();
        p22.setId(22);
        p22.setPermissionLevel("22");
        p22.setApiPath("/goods");
        p22.setPermissionName("商品列表");
        p22.setIcon("iconfont icon-danju");
        p22.setPid(2);
        list2.add(p22);
        p2.setChildren(list2);

        List<Permission> list = new ArrayList<>();
        list.add(p1);
        list.add(p2);
        return new JsonResult(list);
    }
}
